<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>工作调度-案件调度（全局）</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/custom.form.css">
    <style>
        .layui-disabled, .layui-disabled:hover {
            color: #000000 !important;
            cursor: not-allowed !important;
        }

        .layui-form-label {
            width: 100px;
        }

        .layui-input-block {
            width: 500px;
            margin-left: 130px !important;
        }

        fieldset {
            margin-top: 10px;
        }

        .layui-table {
            width: 98%;
        }

        /* 让 radio 和文字对齐 */
        .radio-item {
            display: flex;
            align-items: center;
            gap: 8px; /* 控制单选框和文字之间的距离 */
            margin-bottom: 10px;
            width: 80%;
        }

        /* 让 span 看起来像 layui 的 radio 文字 */
        .name-display {
            color: #333;
            font-size: 14px;
            cursor: pointer;
            transition: color 0.2s ease-in-out;
        }

        /* 选中时的颜色 */
        input[type="radio"]:checked + .name-display {
            color: #009688; /* layui 主题色 */
            font-weight: bold;
        }

        .layui-form-select {
            width: 98%;
        }

    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header"></div>
                <div class="layui-card-body">
                    <!--填写调度-->
                    <div id="Gzdd_Form" class="Gzdd_table" style="display: none">
                        <div class="Gzdd_table-content">
                            <div class="Gzdd_table-item layui-show">
                                <div class="layui-card-body">
                                    <form class="layui-form" lay-filter="info">
                                        <label for="dduuid"></label>
                                        <input type="text" id="dduuid" class="layui-input" style="display: none">
                                        <label for="type"></label>
                                        <input type="text" id="type" class="layui-input" style="display: none">
                                        <!-- 调度名称 -->
                                        <div class="layui-form-item">
                                            <label for="ddmc" class="layui-form-label">填报调度名称</label>
                                            <div class="layui-input-block">
                                                <input id="ddmc" class="layui-input" type="text" placeholder="请填写填报调度名称"
                                                       autocomplete="off">
                                            </div>
                                        </div>
                                        <!-- 调度日期 -->
                                        <div class="layui-form-item">
                                            <label for="contentdate" class="layui-form-label">填报时间</label>
                                            <div class="layui-input-block">
                                                <input type="text"
                                                       class="layui-input" id="contentdate"
                                                       placeholder="请输入填报日期" autocomplete="off">
                                            </div>
                                        </div>
                                        <!-- 选择填报类型 -->
                                        <div id="moldDiv" class="layui-form-item">
                                            <label class="layui-form-label" for="mold">填报类型</label>
                                            <div class="layui-input-block">
                                                <select id="mold" class="layui-input" autocomplete="off" lay-filter="mold"></select>
                                            </div>
                                        </div>
                                        <button type="button" class="layui-btn" id="addAjxx" style="margin-left: 20px">添加案件</button>
                                        <button type="button" class="layui-btn" id="plxpAj">批量下派</button>
                                        <button type="button" class="layui-btn" id="viewDdmb">查看模板</button>
                                        <button type="button" class="layui-btn" id="btn_importTempDownload">导入案件模板下载</button>
                                        <button type="button" class="layui-btn" id="uploadExcel">导入案件</button>
                                        <!-- 实际案件表格-->
                                        <table class="layui-table" id="ajxx_table" lay-filter="ajxx_table"></table>
                                        <div class="layui-form-item" style="display: flex; justify-content: center;">
                                            <button class="layui-btn" type="button" id="submitGzdd">提交</button>
                                            <button class="layui-btn layui-btn-primary" type="button" onclick="back()">返回</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--主页列表-->
                    <div id="Gzdd_table" class="layui-table" style="margin-left: 10px">
                        <div class="Gzdd_table-content">
                            <!--调度列表-->
                            <div class="Gzdd_table table_div">
                                <form id="searchForm" class="layui-form-item">
                                    <div class="layui-input-inline">
                                        <label for="ddmc1"></label>
                                        <input type="text" id="ddmc1" class="layui-input" autocomplete="off"
                                               placeholder="请输入调度名称">
                                    </div>
                                    <div class="layui-input-inline">
                                        <label for="createTime"></label>
                                        <input type="text" readonly class="layui-input" id="createTime" placeholder="创建时间">
                                    </div>
                                    <div class="layui-input-inline layui-form">
                                        <label for="logType"></label>
                                        <select id="logType">
                                            <option value="" disabled selected>请选择调度状态</option>
                                            <option value="3">待调度</option>
                                            <option value="4">调度中</option>
                                            <option value="5">完成</option>
                                            <option value="6">失效</option>
                                        </select>
                                    </div>
                                    <div class="layui-input-inline" style="width: 400px">
                                        <button class="layui-btn" type="button" onclick="searchDd()">查询</button>
                                        <button class="layui-btn" type="button" onclick="resetGzdd()">重置</button>
                                        <button class="layui-btn" type="button" onclick="createGzdd()">创建调度</button>
                                        <button class="layui-btn" type="button" onclick="exportGzdd()">导出</button>
                                    </div>
                                </form>
                                <table class="layui-table" id="ddTable" lay-filter="ddTable"></table>
                            </div>
                        </div>
                    </div>
                    <!-- 添加案件信息 -->
                    <div id="ajxx_able_div" style="display: none">
                        <form id="ajForm" class="layui-form" method="post" style="margin: 15px 0 0 10px">
                            <div class="layui-form-item">
                                <div class="layui-row">
                                    <div class="layui-col-xs3">
                                        <label for="ajbh"></label>
                                        <input type="text" id="ajbh" class="layui-input" autocomplete="off"
                                               placeholder="请输案件编号">
                                    </div>
                                    <div class="layui-col-xs3">
                                        <label for="nsrsbh"></label>
                                        <input type="text" id="nsrsbh" class="layui-input" autocomplete="off"
                                               placeholder="请输纳税人识别号">
                                    </div>
                                    <div class="layui-col-xs3">
                                        <label for="nsrmc"></label>
                                        <input type="text" id="nsrmc" class="layui-input" autocomplete="off"
                                               placeholder="请输入纳税人名称">
                                    </div>
                                    <div class="layui-col-xs3">
                                        <div id="ajztDm"></div>
                                    </div>
                                </div>
                                <div class="layui-row" style="margin-top: 15px;display: flex; justify-content: center;">
                                    <button type="button" class="layui-btn" lay-submit="" lay-filter="searchAj">查询</button>
                                    <button type="button" class="layui-btn" lay-submit="" lay-filter="reset">重置</button>
                                </div>
                            </div>
                            <table id="ajTable" class="layui-table" lay-filter="ajTable"></table>
                        </form>
                    </div>
                    <!--填报工作调度-->
                    <div id="tbGzddForm" style="display: none">
                        <div id="content2and3Div" style="margin-top: 10px"></div>
                    </div>
                    <!--选择调查人下拉选-->
                    <div id="ddjsry" style="display: none">
                        <!-- 竖列单选框 -->
                        <form class="layui-form" style="margin: 20px;">
                            <label class="layui-form-label">选择角色</label>
                            <div class="layui-input-block radio-item">
                                <input type="checkbox" name="role" value="检查人" title="检查环节" lay-skin="primary" lay-filter="role"
                                       checked
                                       style="width: auto">
                                <span id="jcryName" class="name-display"></span>
                            </div>
                            <div class="layui-input-block radio-item">
                                <input type="checkbox" name="role" value="审理人" title="审理环节" lay-skin="primary" lay-filter="role"
                                       style="width: auto">
                                <span id="slryName" class="name-display"></span>
                            </div>
                            <div class="layui-input-block radio-item">
                                <input type="checkbox" name="role" value="执行人" title="执行环节" lay-skin="primary" lay-filter="role"
                                       style="width: auto">
                                <span id="zxryName" class="name-display"></span>
                            </div>
                            <div class="layui-input-block radio-item" style="display: flex; align-items: center;width: 50%">
                                <input type="checkbox" name="role" value="指定人" title="指定人" lay-skin="primary" lay-filter="role"
                                       style="width: auto"
                                       id="roleCheckbox">
                                <label for="jsrSelect"></label>
                                <select name="jsrSelect" lay-filter="jsrSelect" id="jsrSelect" lay-search></select>
                            </div>
                        </form>
                    </div>
                    <!--批量下派-->
                    <div id="plxpjsry" style="display: none">
                        <!-- 竖列单选框 -->
                        <form class="layui-form" style="margin: 20px;">
                            <label class="layui-form-label" style="width: auto">选择角色</label>
                            <div class="layui-input-block radio-item">
                                <input type="checkbox" name="role1" value="检查环节" title="检查环节" lay-skin="primary" lay-filter="role1"
                                       checked
                                       style="width: auto">
                            </div>
                            <div class="layui-input-block radio-item">
                                <input type="checkbox" name="role1" value="审理环节" title="审理环节" lay-skin="primary" lay-filter="role1"
                                       style="width: auto">
                            </div>
                            <div class="layui-input-block radio-item">
                                <input type="checkbox" name="role1" value="执行环节" title="执行环节" lay-skin="primary" lay-filter="role1"
                                       style="width: auto">
                            </div>
                            <div class="layui-input-block radio-item">
                                <input type="checkbox" name="role1" value="实际环节" title="实际环节" lay-skin="primary" lay-filter="role1"
                                       style="width: auto">
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!--启动调度-->
<script type="text/html" id="tool1">
    {{# if(d.type === "7" || d.type === "6"|| d.type === "3"){ }}
    <a class="layui-btn layui-btn-xs" lay-event="startGzdd">启动</a>
    {{# } }}
    <a class="layui-btn layui-btn-xs" lay-event="viewGzdd">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="stopGzdd">暂停</a>
    <a class="layui-btn layui-btn-xs" lay-event="delGzdd">删除</a>
</script>
<script type="text/html" id="tool2">
    <a class="layui-btn layui-btn-xs" lay-event="xpGzdd">下派</a>
    <a class="layui-btn layui-btn-xs" lay-event="tbGzdd">填报</a>
    <a class="layui-btn layui-btn-xs" lay-event="delAj">删除</a>
</script>
<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script src="/layui-ext/selectM/selectM.js"></script>
<script src="/js/xlsx.full.min.js"></script>
<script th:inline="none">
    // 获取token
    let token = CoreUtil.getData("access_token");
    // 地址栏转义token中的#号
    let tokenQuery = token.replace("#", "%23");
    let ddTable;
    let ajTable;
    let ajxx_table;
    let table = layui.table;
    let form = layui.form;
    let layer = layui.layer;
    let util = layui.util;
    let $ = jQuery = layui.jquery;
    let laydate = layui.laydate;
    let upload = layui.upload;
    let element = layui.element;
    let maxlength = 500;
    let inspectionMan = "";
    let mold = "";
    let startTime = null;
    let endTime = null;
    let _surveyDetail = [];
    let ajztDms;
    const selectMAjcx = layui.selectM;
    layui.use(['table', 'layer', 'laydate', 'upload', 'element'], function () {
        //接收人下拉选
        CoreUtil.sendPost("/workflow/activity/querySelectJcr", "", function (res) {
            if (res.code === 0) {
                let value = res.data;
                let opt = "<option value = ''>请选择接收人</option>";
                for (let i in value) {
                    opt += '<option value = "' + value[i].swryxm + '">' + value[i].swryxm + '</option>';
                }
                $("#jsrSelect").html(opt);
                $("#plxpSelect").html(opt);
                form.render('select'); // 指定渲染 id
            } else {
                layer.msg(res.msg);
                return false;
            }
        });
        //案件列表查询
        form.on('submit(searchAj)', function (data) {
            const formData = data.field;
            const ajztDms = formData.ajztDm;
            const whereParams = {
                "nsrsbh": $("#nsrsbh").val(),
                "nsrmc": $("#nsrmc").val(),
                "jcajbh": $("#ajbh").val(),
                "ajjcztDm": ajztDms,
            };
            ajTable.reload({
                contentType: 'application/json'
                , headers: {"authorization": token}
                , where: whereParams
                , url: '/workflow/activity/queryGzddAjxx'//数据接口
                , method: 'POST'
                , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                        "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
                    }
                }, page: {
                    curr: 1 //重新从第 1 页开始
                }
            }, false);
        })
        //页面查询条件重置按钮
        form.on('submit(reset)', function () {
            document.getElementById('ajForm').reset(); // 原生重置表单
            form.render(); // 重新渲染 Layui 的动态组件
            ajztDms.set([]);  // 传入空数组，清空所有已选项
        })
        //案件状态下拉选
        ajztDms = selectMAjcx({
            //元素容器【必填】
            elem: '#ajztDm'
            //候选数据【必填】
            , data:
                [{"id": "2", "name": "在查"}, {"id": "3", "name": "在审"}, {"id": "4", "name": "在执行"},
                    {"id": "901", "name": "办结"}, {"id": "5", "name": "结案"}
                ]
            //默认值
            , tips: '请选择案件状态'
            //最多选中个数，默认5
            //值的分隔符
            , delimiter: ','
            //候选项数据的键名
            , field: {idName: 'id', titleName: 'name'}
        });
        // 填写调度
        form.on('select(mold)', function () {
            let myselect = document.getElementById("mold");
            let index = myselect.selectedIndex; // selectedIndex代表的是你所选中项的index
            mold = myselect.options[index].value;
            // 加载页面
            let mapArr = {
                id: mold
            }
            let content2and3Div = $("#content2and3Div");
            CoreUtil.sendPost("/workflow/log/survey/getGzddContentById", mapArr, function (res) {
                if (res.code === 0) {
                    content2and3Div.html("");
                    let _data = res.data;
                    _surveyDetail = _data;
                    let viewSurveyTmp = "";
                    for (let _i in _data) {
                        let _optionsConent = _data[_i].optionsConent;
                        let _contentSurveyJson = eval("(" + _optionsConent + ")");
                        let _optionsTitle = _data[_i].optionsTitle;
                        let _optionsType = _data[_i].optionsType;
                        let _id = _data[_i].id;
                        let _surveyId = _data[_i].surveyId;
                        if (_optionsType == "1") {
                            // 文本
                            viewSurveyTmp += "<div class='layui-form-item'>"
                                + "<label style='' class='layui-form-label'>" + _optionsTitle + "</label>"
                                + "<div class='layui-input-block'>";
                            if (_contentSurveyJson[0] == "date") {
                                viewSurveyTmp += "<input type='text' name='date' class='layui-date layui-input " + _id + "' placeholder='请输入yyyy-mm-dd格式'>";
                            } else {
                                viewSurveyTmp += "<input type='text' class='layui-input " + _id + "' placeholder='请输入'>";
                            }
                            viewSurveyTmp += "</div><br>";
                        } else if (_optionsType == "2") {
                            let l = Object.keys(_contentSurveyJson).length;
                            // 多选
                            viewSurveyTmp += "<div class='layui-form-item'>"
                                + "<label style='height: " + l * 60 + "px' class='layui-form-label'>" + _optionsTitle + "</label>";
                            for (let _ii in _contentSurveyJson) {
                                /* viewSurveyTmp += "<div class='mui-input-row mui-checkbox mui-left'>"
                                              + "<label class='layui-form-label'>"+_contentSurveyJson[_ii][0]+"</label>"
                                              + "<input class='"+_id+"' name='checkbox1' value='"+_contentSurveyJson[_ii][0]+"' type='checkbox'>"
                                              + "</div>"; */
                                viewSurveyTmp += "<div onclick='optionsDuoxuan(this," + _ii + ")' class='layui-unselect layui-form-checkbox " + _id + "' lay-skin='primary'><div></div><i class='layui-icon layui-icon-ok'></i></div>" + _contentSurveyJson[_ii][0];
                                let flag = _contentSurveyJson[_ii][1];
                                if (flag) {
                                    viewSurveyTmp += "<input style='width: 40%' type='text' class='layui-input " + _id + "_" + _ii + "' placeholder='请输入'>";
                                }
                                viewSurveyTmp += "<br>";
                            }
                            viewSurveyTmp += "<hr>";
                        } else if (_optionsType == "3") {
                            let l = Object.keys(_contentSurveyJson).length;
                            // 单选
                            viewSurveyTmp += "<div class='layui-form-item'>"
                                + "<label style='height: " + l * 60 + "px' class='layui-form-label'>" + _optionsTitle + "</label>";
                            for (let _ii in _contentSurveyJson) {
                                /* viewSurveyTmp += "<div class='layui-form'>"
                                              // + "<label>"+_contentSurveyJson[_ii][0]+"</label>"
                                              + "<input class='"+_id+"' name='radio1_"+_id+"' value='"+_contentSurveyJson[_ii][0]+"' type='radio'>"
                                              + "</div>"; */
                                viewSurveyTmp += "<div onclick='optionsDanxuan(this," + _ii + ")' class='layui-unselect layui-form-radio " + _id + "'><i class='layui-anim layui-icon layui-icon-radio'></i><div>" + _contentSurveyJson[_ii][0] + "</div></div>";
                                let flag = _contentSurveyJson[_ii][1];
                                if (flag) {
                                    viewSurveyTmp += "<input style='width: 40%' type='text' class='layui-input " + _id + "_" + _ii + "' placeholder='请输入'>";
                                }
                                viewSurveyTmp += "<br>";
                            }
                            viewSurveyTmp += "<hr>";
                        }
                    }
                    content2and3Div.html(viewSurveyTmp);
                } else {
                    layer.msg(res.msg);
                    return false;
                }
            });
            //清空表格原来的数据
            let tableData = table.cache['ajxx_table'] || [];
            // 遍历数据并清空 ajContent
            tableData.forEach(row => {
                row.ajContent = "";  // 也可以设置为 null，取决于你的需求
            });
            // 重新加载表格
            ajxx_table.reload({
                data: tableData,  // 使用更新后的数据
                url: "",
                page: {curr: 1}   // 可以根据需要调整分页
            });
        });
        //多选
        form.on('checkbox(role)', function (data) {
            // 取消所有 checkbox 选中状态
            $('input[name="role"]').prop('checked', false);

            // 只保留当前点击的 checkbox 选中状态
            $(data.elem).prop('checked', true);

            // 重新渲染表单
            form.render('checkbox');
        });
        // 填报，并设置默认值为今天
        laydate.render({
            elem: '#contentdate', // 绑定的 input 元素
            type: 'date', // 日期类型
            format: 'yyyy-MM-dd', // 格式
            value: new Date(), // 默认值设为今天
            trigger: 'click' // 点击触发选择
        });
        //创建时间
        laydate.render({
            elem: '#createTime'
            , type: 'datetime'
            , range: '~'
            , done: function (value) {
                if (value !== null && value !== undefined && value !== "") {
                    startTime = value.split("~")[0];
                    endTime = value.split("~")[1];
                } else {
                    startTime = null;
                    endTime = null;
                }
            }
        });
        //填报类型下拉选
        CoreUtil.sendPost("/workflow/log/survey/queryAjddSelect", null, function (res) {
            if (res.code === 0) {
                let value = res.data;
                let opt = "<option value = ''>请选择填报类型</option>";
                for (let i in value) {
                    opt += '<option value="' + value[i].id + '">' + value[i].title + '</option>';
                }
                $("#mold").html(opt);
                form.render('select'); //需要渲染一下
            } else {
                layer.msg(res.msg);
                return false;
            }
        });
        //调度列表
        ddTable = table.render({
            elem: '#ddTable',
            contentType: 'application/json',
            headers: {
                "authorization": token
            },
            page: true, // 开启分页
            where: {
                bz: 1
            },
            url: '/workflow/log/queryGzddLists',//数据接口
            method: 'POST',
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null
                        : CoreUtil.paramsDecrypt(res.data.records)
                }
            },
            cols: [[
                {
                    align: 'center',
                    width: 1,
                    field: 'id',
                    title: '调度编号',
                    hide: true
                }, {
                    align: 'center',
                    width: 200,
                    field: 'createName',
                    title: '创建人',
                    sort: true
                }, {
                    align: 'center',
                    width: 300,
                    field: 'ddmc',
                    title: '调度名称',
                    sort: true
                }, {
                    align: 'center',
                    width: 300,
                    field: 'content1',
                    title: '调度模板',
                    sort: true
                }, {
                    align: 'center',
                    width: 120,
                    field: 'type',
                    title: '调度状态',
                    sort: true,
                    templet: function (d) {
                        // 根据 type 的值返回对应的状态文本
                        if (d.type === '3' || d.type === '7') {
                            return '<span>待调度</span>'; // 橙色
                        } else if (d.type === '4') {
                            return '<span>调度中</span>'; // 绿色
                        } else if (d.type === '5') {
                            return '<span>已完成</span>'; // 蓝色
                        } else if (d.type === '6') {
                            return '<span>失效</span>'; // 红色
                        } else {
                            return '<span>未知状态</span>'; // 默认
                        }
                    }
                }, {
                    align: 'center',
                    width: 220,
                    field: 'tbzt',
                    title: '填报状态',
                    sort: true
                }, {
                    align: 'center',
                    width: 140,
                    field: 'contentdate',
                    title: '创建日期',
                    sort: true, templet: function (d) {
                        if (!d.contentdate) {
                            return '';
                        }
                        return layui.util.toDateString(d.contentdate, 'yyyy-MM-dd');
                    }
                }, {
                    align: 'center',
                    width: 140,
                    field: 'updateTime',
                    title: '完成日期',
                    sort: true, templet: function (d) {
                        if (!d.updateTime) {
                            return '';
                        }
                        return layui.util.toDateString(d.updateTime, 'yyyy-MM-dd');
                    }
                }, {
                    fixed: 'right',
                    align: 'center',
                    width: 240,
                    toolbar: "#tool1",
                    title: '操作'
                }
            ]],
        });
        //案件列表
        ajTable = table.render({
            elem: '#ajTable',
            contentType: 'application/json',
            headers: {
                "authorization": token
            },
            where: {
                "bz": 1
            },
            page: true,
            url: '/workflow/activity/queryGzddAjxx',
            method: 'POST',
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null
                        : CoreUtil.paramsDecrypt(res.data.records)
                }
            },
            cols: [[{type: 'checkbox', fixed: 'left'},
                {
                    align: 'center',
                    width: 1,
                    field: 'jcajxxuuid',
                    title: '检查UUID',
                    hide: true
                }, {
                    align: 'center',
                    width: 180,
                    field: 'jcajbh',
                    title: '检查案件编号',
                }, {
                    align: 'center',
                    width: 260,
                    field: 'ajmc',
                    title: '案件名称',
                }, {
                    align: 'center',
                    width: 120,
                    field: 'ajjcztDm',
                    title: '案件状态',
                }, {
                    field: 'larq', title: '立案日期', width: 120, align: "center", templet: function (d) {
                        if (!d.larq) {
                            return '';
                        }
                        return layui.util.toDateString(d.larq, 'yyyy-MM-dd');
                    }
                }, {
                    align: 'center',
                    width: 200,
                    field: 'nsrsbh',
                    title: '纳税人识别号',
                }, {
                    align: 'center',
                    width: 280,
                    field: 'nsrmc',
                    title: '纳税人名称',
                },
            ]],
        });
        //实际案件列表
        ajxx_table = table.render({
            elem: '#ajxx_table',
            contentType: 'application/json',
            headers: {
                "authorization": token
            },
            page: true, // 开启分页
            url: "/workflow/log/queryGzddAjTables",//数据接口
            method: 'POST',
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null
                        : CoreUtil.paramsDecrypt(res.data.records)
                }
            },
            cols: [[{type: 'checkbox', fixed: 'left'},
                {
                    align: 'center',
                    width: 1,
                    field: 'jcajxxuuid',
                    title: '检查UUID',
                    hide: true
                }, {
                    align: 'center',
                    width: 180,
                    field: 'jcajbh',
                    title: '检查案件编号',
                    sort: true
                }, {
                    align: 'center',
                    width: 300,
                    field: 'ajmc',
                    title: '案件名称',
                    sort: true
                }, {
                    align: 'center',
                    width: 120,
                    field: 'ajjcztDm',
                    title: '案件状态',
                    sort: true
                }, {
                    align: 'center',
                    width: 200,
                    field: 'nsrsbh',
                    title: '纳税人识别号',
                    sort: true
                }, {
                    align: 'center',
                    width: 250,
                    field: 'nsrmc',
                    title: '纳税人名称',
                    sort: true
                }, {
                    align: 'center',
                    width: 250,
                    field: 'ddjsry',
                    title: '调度接收人员',
                    sort: true
                }, {
                    align: 'center',
                    width: 120,
                    field: 'ddzt',
                    title: '调度状态',
                    sort: true
                }, {
                    align: 'center',
                    width: 1,
                    field: 'ajContent',
                    title: '调度内容',
                    hide: true
                }, {
                    align: 'center',
                    width: 1,
                    field: 'ajContentId',
                    title: '调度内容id',
                    hide: true
                }, {
                    fixed: 'right',
                    align: 'center',
                    width: 180,
                    toolbar: "#tool2",
                    title: '操作',
                    sort: true
                }
            ]], toolbar: '#toolbar'
        });
        //启动、暂停、修改、删除-工作调度
        table.on('tool(ddTable)', function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case 'startGzdd':
                    CoreUtil.sendPost("/workflow/log/startGzdd/" + data.id, null, function (res) {
                        layer.msg(res.msg);
                        searchDd();
                    });
                    break;
                case 'delGzdd':
                    layer.open({
                        content: '确定要删除么？',
                        yes: function (index) {
                            layer.close(index); //如果设定了yes回调，需进行手工关闭
                            CoreUtil.sendPost("/workflow/log/deleteGzdd/" + data.id, null, function (res) {
                                layer.msg(res.msg);
                                searchDd();
                            });
                        }
                    });
                    break;
                case 'stopGzdd':
                    layer.open({
                        content: '确定要暂停么',
                        yes: function (index) {
                            layer.close(index); //如果设定了yes回调，需进行手工关闭
                            CoreUtil.sendPost("/workflow/log/stopGzdd/" + data.id, null, function (res) {
                                layer.msg(res.msg);
                                searchDd();
                            });
                        }
                    });
                    break;
                case 'viewGzdd':
                    $("#Gzdd_Form").show();
                    $("#Gzdd_table").hide();
                    //主键
                    $("#dduuid").val(data.id);
                    //调度名称
                    $("#ddmc").val(data.ddmc);
                    //调度状态
                    $("#type").val(data.type);
                    //调度日期
                    $("#contentdate").val(data.contentdate);
                    //调度模板名称
                    setMold(data.mold);
                    ajxx_table.reload({
                        contentType: 'application/json',
                        headers: {
                            "authorization": token
                        },
                        where: {
                            "id": data.id,
                            "jcajxxuuids": data.jcajxxuuids
                        },
                        url: "/workflow/log/queryGzddAjTables",
                        page: {
                            curr: 1
                        }
                    });
                    let mapArr = {
                        id: data.mold,
                    };
                    CoreUtil.sendPost("/workflow/log/survey/getGzddContentById", mapArr, function (res) {
                        let content2and3Div = $("#content2and3Div");
                        if (res.code === 0) {
                            content2and3Div.html("");
                            let _data = res.data;
                            _surveyDetail = _data;
                            let viewSurveyTmp = "";
                            for (let _i in _data) {
                                let _optionsConent = _data[_i].optionsConent;
                                let _contentSurveyJson = eval("(" + _optionsConent + ")");
                                let _optionsTitle = _data[_i].optionsTitle;
                                let _optionsType = _data[_i].optionsType;
                                let _id = _data[_i].id;
                                let _surveyId = _data[_i].surveyId;
                                if (_optionsType == "1") {
                                    // 文本
                                    viewSurveyTmp += "<div class='layui-form-item'>"
                                        + "<label style='' class='layui-form-label'>" + _optionsTitle + "</label>"
                                        + "<div class='layui-input-block'>";
                                    if (_contentSurveyJson[0] == "date") {
                                        viewSurveyTmp += "<input type='text' name='date' class='layui-date layui-input " + _id + "' placeholder='请输入yyyy-mm-dd格式'>";
                                    } else {
                                        viewSurveyTmp += "<input type='text' class='layui-input " + _id + "' placeholder='请输入'>";
                                    }
                                    viewSurveyTmp += "</div><br>";
                                } else if (_optionsType == "2") {
                                    let l = Object.keys(_contentSurveyJson).length;
                                    // 多选
                                    viewSurveyTmp += "<div class='layui-form-item'>"
                                        + "<label style='height: " + l * 60 + "px' class='layui-form-label'>" + _optionsTitle + "</label>";
                                    for (let _ii in _contentSurveyJson) {
                                        /* viewSurveyTmp += "<div class='mui-input-row mui-checkbox mui-left'>"
                                                      + "<label class='layui-form-label'>"+_contentSurveyJson[_ii][0]+"</label>"
                                                      + "<input class='"+_id+"' name='checkbox1' value='"+_contentSurveyJson[_ii][0]+"' type='checkbox'>"
                                                      + "</div>"; */
                                        viewSurveyTmp += "<div onclick='optionsDuoxuan(this," + _ii + ")' class='layui-unselect layui-form-checkbox " + _id + "' lay-skin='primary'><div></div><i class='layui-icon layui-icon-ok'></i></div>" + _contentSurveyJson[_ii][0];
                                        let flag = _contentSurveyJson[_ii][1];
                                        if (flag) {
                                            viewSurveyTmp += "<input style='width: 40%' type='text' class='layui-input " + _id + "_" + _ii + "' placeholder='请输入'>";
                                        }
                                        viewSurveyTmp += "<br>";
                                    }
                                    viewSurveyTmp += "<hr>";
                                } else if (_optionsType == "3") {
                                    let l = Object.keys(_contentSurveyJson).length;
                                    // 单选
                                    viewSurveyTmp += "<div class='layui-form-item'>"
                                        + "<label style='height: " + l * 60 + "px' class='layui-form-label'>" + _optionsTitle + "</label>";
                                    for (let _ii in _contentSurveyJson) {
                                        /* viewSurveyTmp += "<div class='layui-form'>"
                                                      // + "<label>"+_contentSurveyJson[_ii][0]+"</label>"
                                                      + "<input class='"+_id+"' name='radio1_"+_id+"' value='"+_contentSurveyJson[_ii][0]+"' type='radio'>"
                                                      + "</div>"; */
                                        viewSurveyTmp += "<div onclick='optionsDanxuan(this," + _ii + ")' class='layui-unselect layui-form-radio " + _id + "'><i class='layui-anim layui-icon layui-icon-radio'></i><div>" + _contentSurveyJson[_ii][0] + "</div></div>";
                                        let flag = _contentSurveyJson[_ii][1];
                                        if (flag) {
                                            viewSurveyTmp += "<input style='width: 40%' type='text' class='layui-input " + _id + "_" + _ii + "' placeholder='请输入'>";
                                        }
                                        viewSurveyTmp += "<br>";
                                    }
                                    viewSurveyTmp += "<hr>";
                                }
                            }
                            content2and3Div.html(viewSurveyTmp);
                        } else {
                            layer.msg(res.msg);
                            return false;
                        }
                    });
                    break;
            }
        });
        //下派、填报、删除
        table.on('tool(ajxx_table)', function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case 'xpGzdd':
                    data.dduuid = $("#dduuid").val();
                    // 这里是赋值
                    document.getElementById("jcryName").innerText = data.jcry || "无";
                    document.getElementById("slryName").innerText = data.slry || "无";
                    document.getElementById("zxryName").innerText = data.zxry || "无";
                    // 弹窗逻辑
                    layer.open({
                        type: 1, // page 层类型
                        skin: 'layui-layer-molv',
                        area: ['60%', '500px'],
                        title: '调度接收人员',
                        shade: 0.6, // 遮罩透明度
                        shadeClose: true, // 点击遮罩区域，关闭弹层
                        maxmin: true, // 允许全屏最小化
                        anim: 0, // 0-6 的动画形式，-1 不开启
                        content: jQuery("#ddjsry"),
                        btn: ['下派', '取消'],
                        yes: function (index) {
                            let selectedValues = [];
                            $('input[name="role"]:checked').each(function () {
                                selectedValues.push($(this).val()); // 将每个选中的复选框的值存入数组
                            });
                            // 初始化拼接后的值
                            let finalValue = '';

                            // 根据选中的值拼接对应的数据
                            let valuesToJoin = [];

                            if (selectedValues.includes('审理人') && data.slry) {
                                valuesToJoin.push(data.slry); // 如果有"审理人"，就加上data.slry
                            }
                            if (selectedValues.includes('执行人') && data.zxry) {
                                valuesToJoin.push(data.zxry); // 如果有"执行人"，就加上data.zxry
                            }
                            if (selectedValues.includes('检查人') && data.jcry) {
                                valuesToJoin.push(data.jcry); // 如果有"检查人"，就加上data.jcry
                            }
                            // 将选中的值以逗号拼接
                            finalValue = valuesToJoin.join(','); // 逗号和空格分隔
                            // 获取复选框元素
                            let checkbox = document.getElementById("roleCheckbox");
                            // 判断复选框是否没有被选中
                            let jsrSelect = checkbox.checked ? $('#jsrSelect').val() : null;
                            let ddjsry = jsrSelect || finalValue
                            let tableData = table.cache['ajxx_table'] || [];
                            let updatedRow = tableData.find(row => row.jcajxxuuid === data.jcajxxuuid);
                            if (updatedRow) {
                                updatedRow.ddjsry = ddjsry;  // 更新该行的“ddjsry”列
                            }
                            // 重新加载表格
                            ajxx_table.reload({
                                data: tableData,  // 使用更新后的数据
                                url: "",
                                page: {curr: 1}   // 可以根据需要调整分页
                            });
                            layer.close(index); // 关闭弹窗
                        },
                    });
                    break;
                case 'tbGzdd':
                    if ($("#content2and3Div").children().length <= 0) {
                        layer.alert('请先选择调度模板！', {icon: 2, title: '提示'});
                        return false;
                    }
                    //判断是否为修改
                    if (data.ajContent !== null && data.ajContent !== undefined && data.ajContent !== "") {
                        console.log("进修改了")
                        CoreUtil.sendPost("/workflow/log/getGzddTbView", data, function (res) {
                            if (res.code === 0) {
                                // 加载模板
                                var _data = res.data;
                                var viewSurveyTmp = "";
                                for (var _i in _data) {
                                    var _optionsConent = _data[_i].optionsFeedback;
                                    var _optionsTitle = _data[_i].optionsTitle;
                                    var _optionsType = _data[_i].optionsType;
                                    var _id = _data[_i].optionsId;
                                    console.log("_id", _id)
                                    if (_optionsType === "1") {
                                        // 文本
                                        viewSurveyTmp += "<div class='layui-form-item'>"
                                            + "<label style='' class='layui-form-label'>" + _optionsTitle + "</label>"
                                            + "<div class='layui-input-block'>"
                                            + "<input   type='text' class='layui-unselect  layui-input " + _id + "' value='" + _optionsConent + "'>"
                                            + "</div>";
                                        viewSurveyTmp += "<hr>";
                                    } else if (_optionsType === "2") {
                                        var _contentSurveyJson = eval("(" + _optionsConent + ")");
                                        var l = Object.keys(_contentSurveyJson).length;
                                        // 多选
                                        viewSurveyTmp += "<div class='layui-form-item'>"
                                            + "<label style='height: " + l * 60 + "px' class='layui-form-label'>" + _optionsTitle + "</label>";

                                        for (var _ii in _contentSurveyJson) {
                                            // 获取当前选项的 uuid 和 selected 状态
                                            const option = _contentSurveyJson[_ii];
                                            const uuid = option.uuid;
                                            const selected = option.selected; // true 或 false

                                            // 根据 selected 状态设置是否选中
                                            const checkedClass = selected ? "layui-form-checked" : "";

                                            // 渲染选项
                                            viewSurveyTmp += "<div onclick='optionsDuoxuan(this," + _ii + ")' class='layui-unselect layui-form-checkbox " + checkedClass + " " + _id + "' lay-skin='primary'>"
                                                + "<div></div>"
                                                + "<i class='layui-icon layui-icon-ok'></i>"
                                                + "</div>" + uuid;  // 显示选项文字

                                            // 如果有额外输入框内容，显示输入框
                                            if (!CoreUtil.isEmpty(option.extraText)) {
                                                viewSurveyTmp += "<input style='width: 40%' type='text' class='layui-unselect layui-input " + _id + "_" + _ii + "' value='" + option.extraText + "'>";
                                            }

                                            viewSurveyTmp += "<br>";
                                        }
                                        viewSurveyTmp += "<hr>";
                                    } else if (_optionsType === "3") {
                                        // 初始渲染
                                        let _contentSurveyJson = eval("(" + _optionsConent + ")");
                                        let l = Object.keys(_contentSurveyJson).length;
                                        // 单选
                                        viewSurveyTmp += "<div class='layui-form-item'>"
                                            + "<label style='height: " + l * 60 + "px' class='layui-form-label'>" + _optionsTitle + "</label>";
                                        for (let _ii in _contentSurveyJson) {
                                            let option = _contentSurveyJson[_ii];
                                            let uuid = option.uuid; // 获取 uuid
                                            let selected = option.selected || false; // 获取是否选中
                                            let extraText = option.extraText || ""; // 获取附加文本框内容

                                            // 判断是否选中，添加选中样式
                                            let checkedClass = selected ? "layui-form-radioed" : "";

                                            // 渲染选项
                                            viewSurveyTmp += "<div onclick='optionsDanxuan(this," + _ii + ")' class='layui-unselect layui-form-radio " + checkedClass + " " + _id + "'><i class='layui-anim layui-icon layui-icon-radio'></i><div>" + uuid + "</div></div>";

                                            // 如果该选项有附加文本框，渲染文本框
                                            if (extraText) {
                                                viewSurveyTmp += "<input style='width: 40%' type='text' class='layui-input " + _id + "_" + _ii + "' value='" + extraText + "'>";
                                            }

                                            viewSurveyTmp += "<br>";
                                        }
                                        viewSurveyTmp += "<hr>";

                                    }
                                }
                                $("#content2and3Div").html(viewSurveyTmp);
                            } else {
                                layer.msg(res.msg);
                            }
                        });
                    }
                    // 在此处输入 layer 的任意代码
                    layer.open({
                        type: 1,
                        skin: 'layui-layer-molv',
                        title: "填报调度",
                        area: ['60%', '500px'],
                        shade: 0.6, // 遮罩透明度
                        maxmin: true, // 允许全屏最小化
                        shadeClose: true,
                        content: jQuery("#tbGzddForm"),
                        btn: ['确定', '取消'],
                        btnAlign: 'c',  // 让按钮居中
                        yes: function (index) {
                            let feelBackArr = [];
                            for (let _i in _surveyDetail) {
                                let _optionsTitle = _surveyDetail[_i].optionsTitle;
                                let _optionsConent = _surveyDetail[_i].optionsConent;
                                let _contentSurveyJson = eval("(" + _optionsConent + ")");
                                let _optionsType = _surveyDetail[_i].optionsType;
                                let _id = _surveyDetail[_i].id;
                                let _surveyId = _surveyDetail[_i].surveyId;
                                if (_optionsType === "1") {
                                    // 文本
                                    let uuid = $("." + _id + "").val();
                                    console.log("uuid", uuid)
                                    if (CoreUtil.isEmpty(uuid)) {
                                        layer.msg(_optionsTitle + "未填写，请填写！");
                                        return false;
                                    }
                                    let map = {
                                        surveyId: _surveyId,
                                        optionsId: _id,
                                        optionsType: _optionsType,
                                        optionsTitle: _optionsTitle,
                                        feelBack: uuid
                                    }
                                    feelBackArr.push(map);
                                } else if (_optionsType === "2") {
                                    // 多选
                                    let _valueArray = [];
                                    for (let _ii in _contentSurveyJson) {
                                        let _className = $("." + _id + "")[_ii].className;
                                        let uuid = _contentSurveyJson[_ii][0];
                                        let flag = _contentSurveyJson[_ii][1];

                                        // 判断是否选中，如果选中就保存
                                        if (_className.indexOf("layui-form-checked") !== -1) {
                                            // 如果选项需要额外填写文本框
                                            if (flag) {
                                                let _text = $("." + _id + "_" + _ii).val();
                                                if (CoreUtil.isEmpty(_text)) {
                                                    layer.msg(_optionsTitle + "," + _contentSurveyJson[_ii][0] + "未选择后，未填写！");
                                                    return false;
                                                } else {
                                                    uuid += "_" + _text; // 合并选项的值和填写的文本
                                                }
                                            }
                                            _valueArray.push({uuid: uuid, selected: true});
                                        } else {
                                            // 保存未选中的选项
                                            _valueArray.push({uuid: uuid, selected: false});
                                        }
                                    }
                                    let map = {
                                        surveyId: _surveyId,
                                        optionsId: _id,
                                        optionsType: _optionsType,
                                        optionsTitle: _optionsTitle,
                                        feelBack: _valueArray
                                    };
                                    feelBackArr.push(map);
                                    // 检查是否至少选择了一个选项
                                    if (_valueArray.filter(item => item.selected).length === 0) {
                                        layer.msg(_optionsTitle + "未选择，请选择！");
                                        return false;
                                    }

                                } else if (_optionsType === "3") {
                                    // 单选
                                    let _length = $("." + _id).length;
                                    let feelBackArray = []; // 用来保存选项数据

                                    for (_i = 0; _i < _length; _i++) {
                                        let _className = $("." + _id)[_i].className;
                                        let uuid = _contentSurveyJson[_i][0]; // 获取选项的 uuid
                                        let isSelected = _className.indexOf("layui-form-radioed") !== -1; // 判断是否选中
                                        let flag = _contentSurveyJson[_i][1]; // 判断是否有附加文本框

                                        // 如果选中，将该选项加入 feelBackArray
                                        feelBackArray.push({
                                            uuid: uuid,
                                            selected: isSelected
                                        });

                                        // 如果该选项有附加文本框且选中了，保存文本框的值
                                        if (isSelected && flag) {
                                            let _text = $("." + _id + "_" + _i).val();
                                            if (CoreUtil.isEmpty(_text)) {
                                                layer.msg(_optionsTitle + "," + uuid + " 未填写！");
                                                return false;
                                            } else {
                                                feelBackArray[feelBackArray.length - 1].extraText = _text; // 保存附加文本框的内容
                                            }
                                        }
                                    }

                                    // 如果没有选项被选中，弹出提示
                                    if (feelBackArray.every(item => !item.selected)) {
                                        layer.msg(_optionsTitle + " 未选择，未填写！");
                                        return false;
                                    }

                                    let map = {
                                        surveyId: _surveyId,
                                        optionsId: _id,
                                        optionsType: _optionsType,
                                        optionsTitle: _optionsTitle,
                                        feelBack: feelBackArray
                                    };
                                    feelBackArr.push(map);
                                }
                            }
                            let feelBack = JSON.stringify(feelBackArr)
                            let tableData = table.cache['ajxx_table'] || [];
                            let updatedRow = tableData.find(row => row.jcajxxuuid === data.jcajxxuuid);
                            if (updatedRow) {
                                updatedRow.ajContent = feelBack;  // 更新该行的“ddjsry”列
                            }
                            // 重新加载表格
                            ajxx_table.reload({
                                data: tableData,  // 使用更新后的数据
                                url: "",
                                page: {curr: 1}   // 可以根据需要调整分页
                            });
                            layer.close(index);
                        }
                    });
                    break;
                case 'delAj':
                    // 获取当前表格的所有数据
                    let oldData = table.cache['ajxx_table'] || [];

                    // 过滤掉要删除的那一行数据
                    let newData = oldData.filter(item => item.jcajxxuuid !== data.jcajxxuuid);

                    // 重新加载表格数据
                    ajxx_table.reload({
                        page: {curr: 1},
                        url: '',
                        data: newData // 追加后的数据
                    });
                    break
            }
        });
        //选择案件
        $('#addAjxx').on('click', function () {
            layer.open({
                type: 1, // page 层类型
                skin: 'layui-layer-molv',
                area: ['80%', '500px'],
                title: '案件信息',
                shade: 0.6, // 遮罩透明度
                shadeClose: true, // 点击遮罩区域，关闭弹层
                maxmin: true, // 允许全屏最小化
                anim: 0, // 0-6 的动画形式，-1 不开启
                content: jQuery("#ajxx_able_div"),
                btn: ['确定', '取消'],
                btnAlign: 'c',  // 让按钮居中
                yes: function (index) {
                    // 获取选中的数据
                    let checkStatus = table.checkStatus('ajTable'); // 参数为表格的 id
                    let formattedData = checkStatus.data.map(item => ({
                        jcajxxuuid: item.jcajxxuuid,
                        jcajbh: item.jcajbh,
                        ajmc: item.ajmc,
                        ajjcztDm: item.ajjcztDm,
                        jcry: item.jcry,
                        slry: item.slry,
                        zxry: item.zxry,
                        nsrsbh: item.nsrsbh,
                        nsrmc: item.nsrmc
                    }));
                    // 获取当前表格已有的数据
                    let oldData = table.cache['ajxx_table'] || [];

                    // 将新数据追加到旧数据后
                    let newData = oldData.concat(formattedData);

                    // 重新渲染表格，数据合并
                    ajxx_table.reload({
                        where: {bz: 1},
                        page: {curr: 1},
                        url: '',
                        data: newData // 追加后的数据
                    });
                    // 案件的表格也需要刷新一下
                    table.reload('ajTable', {where: {}})
                    layer.close(index); // 关闭弹层
                },
            });
        });
        //提交工作调度
        $('#submitGzdd').on('click', function () {
            // 判断调度名称
            const ddmc = $("#ddmc").val();
            if (CoreUtil.isEmpty(ddmc)) {
                layer.alert('请填写调度名称！', {icon: 2, title: '提示'});
                return false;
            }
            if ($("#content2and3Div").children().length <= 0) {
                layer.alert('请先选择调度模板！', {icon: 2, title: '提示'});
                return false;
            }
            // 调度状态
            const type = $("#type").val();
            // 获取当前表格所有数据
            let allData = table.cache['ajxx_table'];
            // 提取所有数据中的 jcajxxuuid 字段
            let jcajxxuuidArray = allData.map(function (item) {
                return item.jcajxxuuid;
            });
            //传递
            let mapArr = {
                //调度主键
                id: $("#dduuid").val(),
                //调度名称
                ddmc: ddmc,
                //调度状态
                type: type,
                //调度时间
                contentdate: $("#contentdate").val(),
                //调度模板-主键
                mold: $("#mold").val(),
                //稽查案件主键
                jcajxxuuids: JSON.stringify(jcajxxuuidArray),
                //案件List
                ajList: allData,
                //标志位
                bz: 1
            }
            CoreUtil.sendPost("/workflow/log/addGzdd", mapArr, function (res) {
                if (res.code === 0) {
                    searchDd();
                    layer.msg("创建案件调度成功！", {icon: 1});
                    back();
                } else {
                    layer.msg(res.msg, {icon: 2});
                    return false;
                }
            });
        });
        //批量下派案件
        $('#plxpAj').on('click', function () {
            let checkStatus = table.checkStatus('ajxx_table'); // 参数为表格的 id
            // 表格选中数据
            let data = checkStatus.data;
            if (!data || data.length === 0) {
                layer.alert('请先添加案件，选择需要批量下派的数据!', {icon: 2, title: '提示'});
                return false;
            }
            layer.open({
                type: 1, // page 层类型
                skin: 'layui-layer-molv',
                area: ['60%', '400px'],
                title: '批量下派',
                shade: 0.6, // 遮罩透明度
                shadeClose: true, // 点击遮罩区域，关闭弹层
                maxmin: true, // 允许全屏最小化
                anim: 0, // 0-6 的动画形式，-1 不开启
                content: jQuery("#plxpjsry"),
                btn: ['确定', '取消'],
                btnAlign: 'c',  // 让按钮居中
                yes: function (index) {
                    // 获取用户选择的角色
                    let selectedRoles = [];
                    document.querySelectorAll('input[name="role1"]:checked').forEach(function (checkbox) {
                        selectedRoles.push(checkbox.value);
                    });

                    // 获取表格缓存数据
                    let tableData = table.cache['ajxx_table'] || [];

                    // 遍历表格数据
                    tableData.forEach(function (row) {
                        // 初始化 ddjsry 为一个空数组，用于存储多个角色的值
                        let ddjsryValues = [];

                        // 根据选择的角色设置 ddjsry
                        if (selectedRoles.includes("审理环节")) {
                            if (row.slry) {
                                ddjsryValues.push(row.slry);
                            }
                        }
                        if (selectedRoles.includes("检查环节")) {
                            if (row.jcry) {
                                ddjsryValues.push(row.jcry);
                            }
                        }
                        if (selectedRoles.includes("执行环节")) {
                            if (row.zxry) {
                                ddjsryValues.push(row.zxry);
                            }
                        }
                        if (selectedRoles.includes("实际环节")) {
                            // 根据 ajjcztDm 判断
                            if (row.ajjcztDm) {
                                if (row.ajjcztDm.includes("执行")) {
                                    if (row.zxry) {
                                        ddjsryValues.push(row.zxry);
                                    }
                                } else if (row.ajjcztDm.includes("审理")) {
                                    if (row.slry) {
                                        ddjsryValues.push(row.slry);
                                    }
                                } else if (row.ajjcztDm.includes("检查")) {
                                    if (row.jcry) {
                                        ddjsryValues.push(row.jcry);
                                    }
                                }
                            }
                        }

                        // 将多个值拼接成一个字符串，用逗号分隔
                        if (ddjsryValues.length > 0) {
                            row.ddjsry = ddjsryValues.join(", ");
                        } else {
                            row.ddjsry = "暂无人员";
                        }
                    });

                    // 更新表格数据
                    table.reload('ajxx_table', {
                        data: tableData,
                        url: "",
                        page: {
                            curr: 1 // 重新回到第一页
                        }
                    });
                    console.log("更新后的 tableData:", tableData);
                    // 案件的表格也需要刷新一下
                    layer.close(index); // 关闭弹层
                    // 清除所有选中状态
                    table.cache['ajxx_table'].forEach(row => {
                        row.LAY_CHECKED = false; // 取消选中状态
                    });
                    // 重新渲染表格
                    ajxx_table.reload({
                        data: table.cache['ajxx_table'] // 使用更新后的缓存数据
                    });
                },
            });
        });
        //查看调度模板
        $('#viewDdmb').on('click', function () {
            if ($("#content2and3Div").children().length <= 0) {
                layer.alert('请先选择调度模板！', {icon: 2, title: '提示'});
                return false;
            }
            // 在此处输入 layer 的任意代码
            layer.open({
                type: 1,
                skin: 'layui-layer-molv',
                title: "填报调度",
                area: ['60%', '500px'],
                shade: 0.6, // 遮罩透明度
                maxmin: true, // 允许全屏最小化
                shadeClose: true,
                content: jQuery("#tbGzddForm"),
                btn: ['返回'],
                btnAlign: 'c',  // 让按钮居中
            });
        });
        //导入模板下载
        $("#btn_importTempDownload").click(function () {
            var a = document.createElement('a');
            a.setAttribute('href', 'http://72.1.9.104/files/tmeplate.xlsx');
            a.setAttribute('target', '_blank');
            a.setAttribute('id', 'js_a');
            //防止反复添加
            if (document.getElementById('js_a')) {
                document.body.removeChild(document.getElementById('js_a'));
            }
            document.body.appendChild(a);
            a.click();
        });

        // 文件上传配置
        upload.render({
            elem: '#uploadExcel', // 绑定按钮
            headers: {"authorization": token},
            url: '/workflow/log/uploadGzddExcel',  // 上传接口地址
            accept: 'file',       // 允许上传的文件类型
            exts: 'xlsx|xls',     // 允许上传的文件后缀
            done: function (res) {
                if (res.code === 0) {
                    layer.msg('导入成功', {icon: 1});
                    ajxx_table.reload({
                        contentType: 'application/json',
                        data: res.data.records, // 重新渲染数据
                        url: "",
                        page: {
                            curr: 1
                        }
                    });
                    console.log('案件编号列表:', res.data); // 打印后端返回的案件编号列表
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            },
            error: function () {
                layer.msg('上传失败', {icon: 2});
            }
        });

        //设置调度模板名称
        function setMold(data) {
            //调度名称
            $("#mold").val(data); // 直接设置选中的值
            layui.form.render('select'); // 重新渲染 select
        }

        // 监听“指定人”复选框的点击事件
        form.on('checkbox(role)', function (data) {
            if (data.elem.id === 'roleCheckbox') {
                const isSpecified = data.elem.checked;
                // 获取其他三个复选框
                const checkboxes = document.querySelectorAll('input[name="role"]:not([value="指定人"])');
                // 如果“指定人”被选中，取消选中其他复选框
                if (isSpecified) {
                    checkboxes.forEach(function (checkbox) {
                        checkbox.checked = false;
                    });
                    form.render('checkbox'); // 重新渲染复选框
                }
            } else {
                // 如果点击了其他复选框，取消选中“指定人”
                const roleCheckbox = document.getElementById('roleCheckbox');
                roleCheckbox.checked = false;
                form.render('checkbox'); // 重新渲染复选框
            }
        });

        // 监听复选框的点击事件
        form.on('checkbox(role1)', function(data) {
            console.log("我进来没")
            const value = data.value;
            const isActual = value === "实际环节";
            const isOther = ["检查环节", "审理环节", "执行环节"].includes(value);

            if (isActual) {
                // 如果点击的是“实际环节”，取消上面三个的勾选
                ["检查环节", "审理环节", "执行环节"].forEach(function(v) {
                    const checkbox = document.querySelector(`input[value="${v}"]`);
                    if (checkbox) {
                        checkbox.checked = false; // 取消勾选
                    }
                });
            } else if (isOther) {
                // 如果点击的是上面三个，取消“实际环节”的勾选
                const actualCheckbox = document.querySelector('input[value="实际环节"]');
                if (actualCheckbox) {
                    actualCheckbox.checked = false; // 取消勾选
                }
            }

            // 重新渲染表单
            form.render();
        });
    });

    //查询调度列表
    function searchDd() {
        ddTable.reload({
            contentType: 'application/json',
            headers: {
                "authorization": token
            },
            where: {
                ddmc: $("#ddmc1").val(),
                type: $("#logType").val(),
                startTime: startTime,
                endTime: endTime,
            },
            url: '/workflow/log/queryGzddLists',//数据接口
            page: {
                curr: 1
            }
        });
    }

    //创建调度
    function createGzdd() {
        $("#Gzdd_Form").show();
        $("#Gzdd_table").hide();
        clearData();
    }

    //清空数据
    function clearData() {
        $("#content2and3Div").empty();
        $('#type').val('');  // 清空输入框
        $('#dduuid').val('');  // 清空输入框
        $('#ddmc').val('');  // 清空输入框
        $('#mold').val('');  // 清空输入框
        layui.form.render('select'); // 重新渲染 select 组件
        ajxx_table.reload({
            data: [], // 重新渲染数据
            url: "",
            page: {
                curr: 1
            }
        });
    }

    //返回
    function back() {
        searchDd();
        // 隐藏
        $("#Gzdd_Form").hide();
        $("#Gzdd_table").show();
        clearData();
    }

    //多选
    function optionsDuoxuan(that, i) {
        let $checkbox = $(that);
        if ($checkbox.hasClass("layui-form-checked")) {
            // 取消选中
            $checkbox.removeClass("layui-form-checked");
        } else {
            // 选中
            $checkbox.addClass("layui-form-checked");
        }
        console.log(that);
    }

    // 单选方法
    function optionsDanxuan(that, i) {
        let className = $(that)[0].className;
        console.log("当前元素的 className:", className); // 调试信息
        // 拆分类名并过滤掉空字符串
        let classArr = className.split(' ').filter(cls => cls.trim() !== "");
        console.log("拆分后的 classArr:", classArr); // 调试信息
        if (classArr.length < 3) {
            console.error("类名数量不足，无法获取唯一标识符");
            return;
        }
        let targetClass = classArr[2]; // 假设第三个类是唯一标识符
        console.log("目标类名:", targetClass); // 调试信息
        if (!targetClass || targetClass.indexOf(".") !== -1 || targetClass.indexOf(" ") !== -1) {
            console.error("目标类名无效:", targetClass);
            return;
        }
        if (className.indexOf("layui-form-radioed") !== -1) {
            // 如果已经选中，则不处理
        } else {
            // 更新当前选项的 UI 状态
            $(that)[0].className = classArr[0] + ' ' + classArr[1] + ' ' + targetClass + " layui-form-radioed";
            // 更新其他选项的 UI 状态
            let length = $("." + targetClass).length;
            for (let _i = 0; _i < length; _i++) {
                if (_i !== i) {
                    $("." + targetClass)[_i].className = classArr[0] + ' ' + classArr[1] + ' ' + targetClass;
                }
            }
        }
    }

    // 已调整点击导出按钮
    function exportGzdd() {
        layer.confirm('确定导出所有数据?', {icon: 3, title: '提示'}, function (index) {
            const mapArr = {
                jcajbh: $("#jcajbh1").val(),
                type: "5",
            };
            CoreUtil.sendPost("/workflow/log/exportGzddLists", mapArr, function (res) {
                if (res.code === 0) {
                    const data = res.data;
                    if (!CoreUtil.isEmpty(data)) {
                        //全部导出
                        table.exportFile(ddTable.config.id, data, 'xls');
                        //导出时阻止页面刷新
                        $(".layui-form-item").submit(function (e) {
                            e.preventDefault();
                        })
                    } else {
                        layer.alert('未查询到需要导出的数据！', {icon: 2});
                    }
                }
            });
            layer.close(index);
        });
    }

    // 重置工作调度
    function resetGzdd() {
        document.getElementById('searchForm').reset(); // 原生重置表单
        form.render(); // 重新渲染 Layui 的动态组件
    }

</script>

</body>
</html>